﻿Imports System.Configuration
Imports Infragistics.Win
Imports Lourdes.BackEnd.BC
Imports Lourdes.BackEnd.Interfaces
Imports Lourdes.BackEnd.View
Imports Lourdes.BackEnd.Modelo
Imports Lourdes.BackEnd
Imports Microsoft.Reporting.WinForms
Public Class Utils
  Public Shared Sub ManejoErrores(ByVal pException As Exception)
    MessageBox.Show("Ha ocurrido el siguiente error: " & pException.Message, "Error")
  End Sub

  Public Shared Function GetValueConf(ByVal pKey As String) As String
    Try
      Return ConfigurationManager.AppSettings.Get(pKey)
    Catch ex As Exception
      Throw New Exception("Ocurrio un error al intentar leer el valor de """ & pKey & """ del archivo de configuración. Verifique que el mismo existe.")
    End Try
  End Function

  Public Shared Function getIntFromEditor(pEditor As UltraWinEditors.UltraNumericEditor) As Integer?
    If pEditor.Value IsNot Nothing AndAlso IsNumeric(pEditor.Value) Then
      Return CInt(pEditor.Value)
    Else
      Return New Nullable(Of Integer)
    End If
  End Function

  Public Shared Sub ShowReport(pReporteTipo As Enums.ReporteTipos, pParams As ReportParameterCollection, pForm As Form)
    Dim frm As frmReportViewer = New frmReportViewer(pReporteTipo, pParams)
    frm.ShowDialog(pForm)
  End Sub
  Public Shared Sub ShowReport(pReporteTipo As Enums.ReporteTipos, pParaName As String, pParamValue As String, pForm As Form)
    Dim oParams = New ReportParameterCollection
    oParams.Add(New ReportParameter(pParaName, pParamValue))
    ShowReport(pReporteTipo, oParams, pForm)
  End Sub
End Class
